# -*- coding: UTF-8 _*_
import time

import allure

from common.webbase import WebBase
from common.readconfig import ReadConfig

username = ('id', 'account')
password = ('name', 'password')
loginbutton = ('id', 'submit')
host = ReadConfig.parse_yaml(filename='config/webconfig.yaml',key='base.url.login')


class loginpage():
    @allure.step("登录")
    def login(self, driver, url=host,user='admin', pwd='Yw123456', pagename='登录页'):
        zen = WebBase(driver)
        zen.openpage(url)
        zen.sendkey(locator=username, text=user, pagename=pagename, elename='用户名')
        zen.sendkey(locator=password, text=pwd, pagename=pagename, elename='密码')
        zen.click(locator=loginbutton, pagename=pagename, elename='登录按钮')
        time.sleep(5)
        # zen.save_myscreenshot(pagename=pagename)

    @allure.step("登录成功校验")
    def login_success(self, driver, check='', pagename='首页'):
        zen = WebBase(driver)
        r = zen.istitle(pagename=pagename, check=check)
        # zen.save_myscreenshot(pagename=pagename)
        return r

    @allure.step("登录失败校验")
    def login_fail(self, driver, check='', pagename='首页'):
        zen = WebBase(driver)
        zen.alertaccept(pagename=pagename)
        result = zen.istitle(pagename=pagename, check=check)
        # zen.save_myscreenshot(pagename=pagename)
        return result

    @allure.step("退出")
    def logout(self, driver):
        zen = WebBase(driver)
        zen.logout()
        # zen.save_myscreenshot()
